﻿using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Ext.Direct.Mvc
{
    public class DirectMvcHandler : MvcHandler
    {
        public DirectMvcHandler(RequestContext requestContext) : base(requestContext) {}

        protected override void ProcessRequest(HttpContextBase httpContext) {
            DirectProvider provider = DirectProvider.GetCurrentProvider();

            if (httpContext.Request.RequestType == "GET") {

                // Write Ext.Direct API

                httpContext.Response.ContentType = "text/javascript";
                httpContext.Response.Write(provider.ToString());

            } else {

                // Process Ext.Direct requests

                provider.Execute(this.RequestContext);
            }
        }
    }
}
